﻿using Asxsyd92Core.Utils;
using Asxsyd92Core.Utils.Provider;
using System;
using System.Collections.Generic;
using System.Linq;
using WebOS.Dal;
using WebOS.Modle;
namespace WebOS.Bll
{
    public class RouteBll
    {
        public static RouteBll Instance
        {
            get { return SingletonProvider<RouteBll>.Instance; }
        }

        public List<Route> GetList()
        {
            return RouteDal.Instance.GetAll().ToList();
        }
        public string GetList(string title, int page, int limit)
        {
            string counts = "(select count(1) from Route where 1=1";
            string sqls = "", f = "";
            string sql = "";

            if (title != "" && title != null)
            {
                title = "'%" + title + "%'";
                sql = sql + " and Name like " + title;
                counts = counts + " and Name like " + title;
                f = f + " and Name like " + title;
            }

            //降序
            sql = sql + "and RowNumber > " + limit + " * (" + page + " - 1)";
            //分页
            var fy = "(SELECT ROW_NUMBER() OVER(ORDER BY id DESC) AS RowNumber,*FROM Route where  1=1" + f + ")";
            sqls = "select top " + limit + "  *," + counts + ") as Count  from " + fy + " as A where  1=1 " + sql;
            var da = RouteDal.Instance.GetList(sqls, new { }).ToList();

            return JSONhelper.ToJson(new { code = 0, msg = "", count = da.Count == 0 ? 0 : da.First().Count, data = da }, false);

        }

        public int Insert(Route route)
        {
            return RouteDal.Instance.Insert(route);
        }
        public int Update(Route route)
        {

            return RouteDal.Instance.Update(route);
        }
        public int Delete(Guid id)
        {

            return RouteDal.Instance.Delete(id);
        }
    }
}
